<?php
/**
 * Created by PhpStorm.
 * User: tandunzhao
 * Date: 2018/5/30
 * Time: 下午1:47
 */

namespace App\Modules\Shop\Services;


use App\Modules\Shop\Models\Cart;
use App\Modules\Shop\Models\Coupon;

class CartService
{
    public static function getCartListByUid($uid) {
        return Cart::getCartListByUid($uid);
    }

    public static function addOne($data) {
        return Cart::create($data);
    }

    public static function getByProductSpecIdAndUid($spec_id,$uid) {
        return Cart::where('product_spec_id',$spec_id)->where('uid',$uid)->first();
    }

    public static function DecreaseGoodsByUidAndSpecId($spec_id,$uid) {
        return Cart::where('product_spec_id',$spec_id)->where('uid',$uid)->decrement('count');
    }

    public static function DelOne($id) {
        return Cart::where('id',$id)->delete();
    }

    public static function getUserCartNum($uid) {
        return Cart::where('uid',$uid)->where('count','>',0)->count('id');
    }

    public static function getListByIds($ids) {
        return Cart::whereIn('id',$ids)->get();
    }
}